from flask import Blueprint
from app.controllers import auth_controller, user_controller, video_controller, interaction_controller
from app.middleware.auth import token_required, admin_required

# 创建蓝图
api_bp = Blueprint('api', __name__, url_prefix='/api')

# 认证相关路由
@api_bp.route('/auth/register', methods=['POST'])
def register():
    return auth_controller.register()

@api_bp.route('/auth/login', methods=['POST'])
def login():
    return auth_controller.login()

@api_bp.route('/auth/profile', methods=['GET'])
@token_required
def get_profile():
    return auth_controller.get_profile()

@api_bp.route('/auth/changePassword', methods=['POST'])
@token_required
def change_password():
    return auth_controller.change_password()

# 用户相关路由
@api_bp.route('/user/profile', methods=['GET'])
@token_required
def get_user_profile():
    return user_controller.get_current_user()

@api_bp.route('/user/profile', methods=['PUT'])
@token_required
def update_user_profile():
    return user_controller.update_current_user()

@api_bp.route('/user/stats', methods=['GET'])
@token_required
def get_user_stats():
    return user_controller.get_user_stats()

@api_bp.route('/user/videos', methods=['GET'])
@token_required
def get_user_videos():
    return user_controller.get_user_videos()

@api_bp.route('/user/favorites', methods=['GET'])
@token_required
def get_user_favorites():
    return user_controller.get_user_favorites()

@api_bp.route('/user/likes', methods=['GET'])
@token_required
def get_user_likes():
    return user_controller.get_user_likes()

# 视频相关路由
# 注意：所有特定路由必须在通用视频详情路由之前定义
@api_bp.route('/videos/recommended', methods=['GET'])
def get_recommended_videos():
    return video_controller.get_recommended_videos()

@api_bp.route('/videos/latest', methods=['GET'])
def get_latest_videos():
    return video_controller.get_latest_videos()

@api_bp.route('/videos/hot', methods=['GET'])
def get_hot_videos():
    return video_controller.get_hot_videos()

@api_bp.route('/videos/slides', methods=['GET'])
def get_slide_videos():
    return video_controller.get_slide_videos()

# 为了兼容测试脚本，添加单数形式的路由
@api_bp.route('/videos/slide', methods=['GET'])
def get_slide_videos_singular():
    return video_controller.get_slide_videos()

@api_bp.route('/videos/category/<category_id>', methods=['GET'])
def get_videos_by_category(category_id):
    return video_controller.get_videos_by_category(category_id)

# 通用视频详情路由必须放在最后，避免与其他特定路由冲突
@api_bp.route('/videos/<video_id>', methods=['GET'])
def get_video_detail(video_id):
    return video_controller.get_video_detail(video_id)

# 互动相关路由
@api_bp.route('/interaction/like', methods=['POST'])
@token_required
def like_video():
    return interaction_controller.like_video()

@api_bp.route('/interaction/unlike', methods=['POST'])
@token_required
def unlike_video():
    return interaction_controller.unlike_video()

@api_bp.route('/interaction/check-like', methods=['GET'])
@token_required
def check_like_status():
    return interaction_controller.check_like_status()

@api_bp.route('/interaction/user-likes', methods=['GET'])
@token_required
def get_user_likes_api():
    return interaction_controller.get_user_likes()

@api_bp.route('/interaction/favorite', methods=['POST'])
@token_required
def favorite_video():
    return interaction_controller.favorite_video()

@api_bp.route('/interaction/unfavorite', methods=['POST'])
@token_required
def unfavorite_video():
    return interaction_controller.unfavorite_video()

@api_bp.route('/interaction/check-favorite', methods=['GET'])
@token_required
def check_favorite_status():
    return interaction_controller.check_favorite_status()

@api_bp.route('/interaction/user-favorites', methods=['GET'])
@token_required
def get_user_favorites_api():
    return interaction_controller.get_user_favorites()

@api_bp.route('/interaction/comment', methods=['POST'])
@token_required
def create_comment():
    return interaction_controller.create_comment()

@api_bp.route('/interaction/comment/<comment_id>', methods=['DELETE'])
@token_required
def delete_comment(comment_id):
    return interaction_controller.delete_comment(comment_id)

@api_bp.route('/interaction/comments/<video_id>', methods=['GET'])
def get_video_comments(video_id):
    return interaction_controller.get_video_comments(video_id)